package cn.edu.zafu.bigdata.cccnnn.workone;

public class StaticDemo {
    static int count = 0;
    int id;
    // 静态初始化块
    static {
        System.out.println("Static block executed");
        count = 0;
    }
    // 实例初始化块
    {
        System.out.println("Instance block executed");
        id = count;
        count++;
    }
    // 构造函数，用于创建实例
    public StaticDemo() {
        System.out.println("Constructor executed for ID: " + id);
    }
    // 静态方法，用于打印当前创建了多少个实例
    public static void displayCount() {
        System.out.println("Total created: " + count);
    }

    public static void main(String[] args) {
        StaticDemo obj1 = new StaticDemo();
        StaticDemo obj2 = new StaticDemo(); // 正确声明并初始化 obj2
        StaticDemo obj3= new StaticDemo();
        StaticDemo.displayCount();
    }
}